package com.ecommerce.dal.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.ecommerce.dal.dao.ICommunicationDAO;
import com.ecommerce.dal.entity.Communication;
import com.ecommerce.dal.util.CustomHibernateDAOSupport;

@Repository("communicationDAO")
public class CommunicationDAO extends CustomHibernateDAOSupport implements
		ICommunicationDAO {

	@Override
	public void save(Communication communication) {
		getHibernateTemplate().save(communication);

	}

	@Override
	public void update(Communication communication) {
		getHibernateTemplate().update(communication);

	}

	@Override
	public void delete(Communication communication) {
		getHibernateTemplate().delete(communication);

	}

	@Override
	public Communication findByCommunicationId(int communicationId) {
		List list = getHibernateTemplate()
				.find("from Communication communication where communicationId=?",
						communicationId);
		return (Communication) ((list != null && list.size()>0) ?  list.get(0) : null) ;
	}

	@Override
	public List<Communication> findAllCommunications() {
		List list = getHibernateTemplate().find("from Communication");
		return ((list != null && list.size()>0) ?  list : null) ;
	}

}
